/*
******************************************************************
**                      uCGUIBuilder                            **
**                  Version:   4.0.0.0                          **
**                     2012 / 04                               **
**                   CpoyRight to: wyl                          **
**              Email:ucguibuilder@163.com                        **
**          This text was Created by uCGUIBuilder               **
******************************************************************/

#include <stddef.h>
#include "GUI.h"
#include "DIALOG.h"

#include "WM.h"
#include "BUTTON.h"
#include "CHECKBOX.h"
#include "DROPDOWN.h"
#include "EDIT.h"
#include "FRAMEWIN.h"
#include "LISTBOX.h"
#include "MULTIEDIT.h"
#include "RADIO.h"
#include "SLIDER.h"
#include "TEXT.h"
#include "PROGBAR.h"
#include "SCROLLBAR.h"
#include "LISTVIEW.h"





//EventsFunctionList
//EndofEventsFunctionList


/*********************************************************************
*
*       static data
*
**********************************************************************
*/

#define GUI_ID_TEXT10   GUI_ID_USER+1
#define GUI_ID_TEXT11   GUI_ID_USER+2
#define GUI_ID_TEXT12   GUI_ID_USER+3
#define GUI_ID_TEXT13   GUI_ID_USER+4
#define GUI_ID_TEXT14   GUI_ID_USER+5
#define GUI_ID_TEXT15   GUI_ID_USER+6
#define GUI_ID_TEXT16   GUI_ID_USER+7


/*********************************************************************
*
*       Dialog resource
*
* This table conatins the info required to create the dialog.
* It has been created by ucGUIbuilder.
*/

static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    { FRAMEWIN_CreateIndirect,  "Reflow Welding",    0,                       0,  0,  320,240,FRAMEWIN_CF_MOVEABLE,0},
    { EDIT_CreateIndirect,      NULL,                GUI_ID_EDIT0,            85, 38, 40, 20, 0,0},
    { EDIT_CreateIndirect,      NULL,                GUI_ID_EDIT1,            85, 72, 40, 20, 0,0},
    { TEXT_CreateIndirect,      "Active Temp",       GUI_ID_TEXT0,            17, 41, 62, 15, 0,0},
    { TEXT_CreateIndirect,      "Reflow Temp",       GUI_ID_TEXT1,            17, 75, 62, 15, 0,0},
    { TEXT_CreateIndirect,      "oC",                GUI_ID_TEXT2,            131,41, 23, 15, 0,0},
    { TEXT_CreateIndirect,      "oC",                GUI_ID_TEXT3,            131,75, 23, 15, 0,0},
    { TEXT_CreateIndirect,      "Setup",             GUI_ID_TEXT4,            32, 14, 47, 18, 0,0},
    { TEXT_CreateIndirect,      "Monitor",           GUI_ID_TEXT5,            181,14, 40, 15, 0,0},
    { TEXT_CreateIndirect,      "10",                GUI_ID_TEXT6,            240,38, 40, 20, 0,0},
    { TEXT_CreateIndirect,      "10",                GUI_ID_TEXT7,            240,72, 40, 20, 0,0},
    { TEXT_CreateIndirect,      "Expect Temp",       GUI_ID_TEXT8,            167,44, 67, 17, 0,0},
    { TEXT_CreateIndirect,      "Actual Temp",       GUI_ID_TEXT9,            167,75, 67, 15, 0,0},
    { TEXT_CreateIndirect,      "oC",                GUI_ID_TEXT10,            286,41, 14, 15, 0,0},
    { TEXT_CreateIndirect,      "oC",                GUI_ID_TEXT11,            286,75, 14, 15, 0,0},
    { BUTTON_CreateIndirect,    "Preheat",           GUI_ID_BUTTON0,          32, 176,100,25, 0,0},
    { BUTTON_CreateIndirect,    "Start",             GUI_ID_BUTTON1,          181,176,100,25, 0,0},
    { TEXT_CreateIndirect,      "Current State:",    GUI_ID_TEXT12,           57, 128,75, 15, 0,0},
    { TEXT_CreateIndirect,      "Service Time:",     GUI_ID_TEXT13,           57, 149,71, 12, 0,0},
    { TEXT_CreateIndirect,      "Standby",           GUI_ID_TEXT14,           151,128,113,15, 0,0},
    { TEXT_CreateIndirect,      "0",                 GUI_ID_TEXT15,           151,149,54, 15, 0,0},
    { TEXT_CreateIndirect,      "s",                 GUI_ID_TEXT16,           211,150,20, 14, 0,0}
};



/*****************************************************************
**      FunctionName:void PaintDialog(WM_MESSAGE * pMsg)
**      Function: to initialize the Dialog items
**                                                      
**      call this function in _cbCallback --> WM_PAINT
*****************************************************************/

void PaintDialog(WM_MESSAGE * pMsg)
{
    WM_HWIN hWin = pMsg->hWin;
    GUI_SetColor(0x000000);
    GUI_DrawLine(7,112,153,112);
    GUI_SetColor(0x000000);
    GUI_DrawLine(153,20,153,112);
    GUI_SetColor(0x000000);
    GUI_DrawLine(7,20,7,112);
    GUI_SetColor(0x000000);
    GUI_DrawLine(67,20,153,20);
    GUI_SetColor(0x000000);
    GUI_DrawLine(7,20,25,20);
    GUI_SetColor(0x000000);
    GUI_DrawLine(160,20,174,20);
    GUI_SetColor(0x000000);
    GUI_DrawLine(160,20,160,112);
    GUI_SetColor(0x000000);
    GUI_DrawLine(303,20,303,112);
    GUI_SetColor(0x000000);
    GUI_DrawLine(205,20,303,20);
    GUI_SetColor(0x000000);
    GUI_DrawLine(160,112,303,112);

}



/*****************************************************************
**      FunctionName:void InitDialog(WM_MESSAGE * pMsg)
**      Function: to initialize the Dialog items
**                                                      
**      call this function in _cbCallback --> WM_INIT_DIALOG
*****************************************************************/

void InitDialog(WM_MESSAGE * pMsg)
{
    WM_HWIN hWin = pMsg->hWin;
    //
    //FRAMEWIN
    //
    FRAMEWIN_SetFont(hWin,&GUI_Font16_1);
    FRAMEWIN_SetTextAlign(hWin,GUI_TA_VCENTER|GUI_TA_CENTER);
    FRAMEWIN_SetTitleHeight(hWin,16);
    //
    //GUI_ID_EDIT0
    //
    EDIT_SetTextAlign(WM_GetDialogItem(hWin,GUI_ID_EDIT0),GUI_TA_VCENTER|GUI_TA_CENTER);
    EDIT_SetText(WM_GetDialogItem(hWin,GUI_ID_EDIT0),"90");
    //
    //GUI_ID_EDIT1
    //
    EDIT_SetTextAlign(WM_GetDialogItem(hWin,GUI_ID_EDIT1),GUI_TA_VCENTER|GUI_TA_CENTER);
    EDIT_SetText(WM_GetDialogItem(hWin,GUI_ID_EDIT1),"260");
    //
    //GUI_ID_TEXT6
    //
    TEXT_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_TEXT6),0xffffff);
    TEXT_SetTextAlign(WM_GetDialogItem(hWin,GUI_ID_TEXT6),GUI_TA_VCENTER|GUI_TA_CENTER);
    //
    //GUI_ID_TEXT7
    //
    TEXT_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_TEXT7),0xffffff);
    TEXT_SetTextAlign(WM_GetDialogItem(hWin,GUI_ID_TEXT7),GUI_TA_VCENTER|GUI_TA_CENTER);
    //
    //GUI_ID_TEXT10
    //
    TEXT_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_TEXT13),0xffffff);
    TEXT_SetTextAlign(WM_GetDialogItem(hWin,GUI_ID_TEXT13),GUI_TA_VCENTER|GUI_TA_CENTER);
    //
    //GUI_ID_TEXT10
    //
    TEXT_SetBkColor(WM_GetDialogItem(hWin,GUI_ID_TEXT14),0xffffff);
    TEXT_SetTextAlign(WM_GetDialogItem(hWin,GUI_ID_TEXT14),GUI_TA_VCENTER|GUI_TA_CENTER);

}




/*********************************************************************
*
*       Dialog callback routine
*/
static void _cbCallback(WM_MESSAGE * pMsg) 
{
    int NCode, Id;
    WM_HWIN hWin = pMsg->hWin;
    switch (pMsg->MsgId) 
    {
        case WM_PAINT:
            PaintDialog(pMsg);
            break;
        case WM_INIT_DIALOG:
            InitDialog(pMsg);
            break;
        case WM_KEY:
            switch (((WM_KEY_INFO*)(pMsg->Data.p))->Key) 
            {
                case GUI_KEY_ESCAPE:
                    GUI_EndDialog(hWin, 1);
                    break;
                case GUI_KEY_ENTER:
                    GUI_EndDialog(hWin, 0);
                    break;
            }
            break;
        case WM_NOTIFY_PARENT:
            Id = WM_GetId(pMsg->hWinSrc); 
            NCode = pMsg->Data.v;        
            switch (Id) 
            {
                case GUI_ID_OK:
                    if(NCode==WM_NOTIFICATION_RELEASED)
                        GUI_EndDialog(hWin, 0);
                    break;
                case GUI_ID_CANCEL:
                    if(NCode==WM_NOTIFICATION_RELEASED)
                        GUI_EndDialog(hWin, 0);
                    break;
                case GUI_ID_EDIT0:
										switch (NCode)
										{
										case WM_NOTIFICATION_VALUE_CHANGED:
											OnEditValueChanged(pMsg);
											break;
										}
										break;
									case GUI_ID_EDIT1:
										switch (NCode)
										{
										case WM_NOTIFICATION_VALUE_CHANGED:
											OnEditValueChanged(pMsg);
											break;
										}
										break;
									case GUI_ID_BUTTON0:
										switch (NCode)
										{
										case WM_NOTIFICATION_RELEASED:
											OnButtonReleased0(pMsg);
											break;
										}
										break;
									case GUI_ID_BUTTON1:
										switch (NCode)
										{
										case WM_NOTIFICATION_RELEASED:
											OnButtonReleased1(pMsg);
											break;
            }
            break;
        default:
            WM_DefaultProc(pMsg);
    }
}


/*********************************************************************
*
*       MainTask
*
**********************************************************************
*/
void MainTask(void) 
{ 
    GUI_Init();
    WM_SetDesktopColor(GUI_WHITE);      /* Automacally update desktop window */
    WM_SetCreateFlags(WM_CF_MEMDEV);  /* Use memory devices on all windows to avoid flicker */
    //PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX);
    //FRAMEWIN_SetDefaultSkin(FRAMEWIN_SKIN_FLEX);
    //PROGBAR_SetDefaultSkin(PROGBAR_SKIN_FLEX);
    //BUTTON_SetDefaultSkin(BUTTON_SKIN_FLEX);
    //CHECKBOX_SetDefaultSkin(CHECKBOX_SKIN_FLEX);
    //DROPDOWN_SetDefaultSkin(DROPDOWN_SKIN_FLEX);
    //SCROLLBAR_SetDefaultSkin(SCROLLBAR_SKIN_FLEX);
    //SLIDER_SetDefaultSkin(SLIDER_SKIN_FLEX);
    //HEADER_SetDefaultSkin(HEADER_SKIN_FLEX);
    //RADIO_SetDefaultSkin(RADIO_SKIN_FLEX);
	while(1)
	{
        GUI_ExecDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), &_cbCallback, 0, 0, 0);
	}
}

